#!/bin/bash

# get disk image
if [ $# -eq 0 ]; then
	echo "ERROR: Image file not found"
	echo "Example of Image file path: result_image/<image_directory>/<image_file>.qcow2"
	exit 1
fi

if [ -f "$1" ]; then
	# file exists - use it
	image_file=$(realpath $1)
else
	# try relative path in build result folder
	image_file=/build/result_image/$1
fi

qemu-system-aarch64 \
	-machine virt \
	-cpu cortex-a72 \
	-m 4096 \
	-nographic \
	-netdev user,id=mynet0,hostfwd=tcp::2222-:22,hostfwd=tcp::1234-:1234 \
	-device virtio-net-pci,netdev=mynet0 \
	-drive file=${image_file},if=virtio  \
	-bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd
